/**
  * By default, this raises a security exception as an applet.
  *
  * With JDK 1.2 appletviewer, 
  *  if you configure your system to grant applets signed by "Duke"
  *  and downloaded from the Java Software Website to write a file
  *  to your /tmp directory (or to the file named "C:\tmpfoo" on a 
  *  Windows system), then this applet can run.
  *  
  * @version JDK 1.2
  * @author  Marianne Mueller
  * @Modified by Raghavan Srinivas[Rags]
  */

import java.awt.*;
import java.io.*;
import java.lang.*;
import java.applet.*;

public class writeFile extends Applet {
    String myFile = "/tmp/foo";
    File f = new File(myFile);
    DataOutputStream dos;

  public void init() {
    
    String osname = System.getProperty("os.name");
    if (osname.indexOf("Windows") != -1) {
      myFile="C:" + File.separator + "tmpfoo";
    }
  }

  public void paint(Graphics g) {
	try {
  	  dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(myFile),128));
	  dos.writeBytes("Cats can hypnotize you when you least expect it\n");
	  dos.flush();
	  dos.close();
	  g.drawString("Successfully wrote to the file named " + myFile + " -- go take a look at it!", 10, 10);
	}


	catch (SecurityException e) {
	  g.drawString("writeFile: caught security exception", 10, 10);
        }
	catch (IOException ioe) {
		g.drawString("writeFile: caught i/o exception", 10, 10);
        }
   }
    public static void main(String args[]) {
	Frame f = new Frame("writeFile");
	writeFile	writefile = new writeFile();

	writefile.init();
	writefile.start();

	f.add("Center", writefile);
	f.setSize(300, 100);
	f.show();
    }
}
